package StudyCode.summary.mycollection;

import java.util.Enumeration;
import java.util.Vector;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CreateVectorFromArray {
	public static void main(String[] argv) {
		Object[] array = new String[]{"1", "abc", "level", null,
				"java2s.com", "asdf 123"};
		System.out.println(createVector(array));
	}

	public static Vector createVector(Object[] array) {
		return appendInto(new Vector(), array);
	}

	public static Vector createVector(Enumeration e) {
		Vector result = new Vector();
		while (e.hasMoreElements())
			result.addElement(e.nextElement());
		return result;
	}

	public static Vector appendInto(Vector v, Object[] array) {
		appendInto(v, array, array.length);
		return v;
	}

	public static Vector appendInto(Vector v, Object[] array, int quantity) {
		v.ensureCapacity(v.size() + quantity);
		for (int i = 0; i < quantity; i++) {
			v.addElement(array[i]);
		}

		return v;
	}

	public static Vector appendInto(Vector dest, Vector src) {
		Enumeration e = src.elements();
		while (e.hasMoreElements())
			dest.addElement(e.nextElement());
		return dest;
	}
}
